<%@ page import="main.java.domain.Task" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./css/bootstrap/dist/css/bootstrap.css">
    <link rel="stylesheet" href="./css/download.css">
    <link rel="stylesheet" href="./css/upload.css">
    <script src="./js/upload.js"></script>
    <style>
        .file-box {
            width: 340px;
        }

        .file-box:last-child::after {
            display: block;
            content: "";
            clear: both;
        }

        .upload-box {
            margin-top: 20px;;
        }
    </style>
    <title>详情</title>
</head>

<body>
<div class="container">
    <!-- page-header -->
    <a href="${pageContext.request.contextPath}/correctionServlet?task_id=${pageContext.request.getParameter("task_id")}" type="button" class="btn btn-info" aria-label="Left Align">
        <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
        返回
    </a>

    <hr style="border: 1px solid #ddd;">


    <div>
        <p>${fn:length(filenames)}个附件</p>
        <div class="file-box">
            <c:forEach items="${filenames}" var="file">
                <div class="download-box" onclick="downloadHandle('${file}')">
                    <div class="file-img glyphicon glyphicon-cloud-download"></div>
                    <div class="file-name">${file.split("/")[fn:length(file.split("/"))-1]}</div>
                </div>
            </c:forEach>
        </div>
    </div>

    <form class="form-horizontal" action="${pageContext.request.contextPath}/updateResultServlet" method="get">
        <div class="form-group">
            <label for="" class="col-sm-2 control-label">作业分数</label>
            <div class="col-sm-10">
                <input name="res" type="text" class="form-control" placeholder="请输入分数">
            </div>
        </div>
        <div class="form-group">
            <label for="" class="col-sm-2 control-label">描述(作业评价)</label>
            <div class="col-sm-10">
                    <textarea name="eval" style="resize: vertical;" class="form-control" rows="4"
                              placeholder="请输入作业评价（可选）"></textarea>
            </div>
        </div>

        <input type="submit" style="display: none" id="submit">
    </form>

    <hr style="border: 1px solid #ddd;">

    <div class="submit-item">
        <button onclick="submitHandle()" type="button" class="btn btn-success">提交</button>
    </div>
</div>

<script>
    function submitHandle() {
        const res = document.querySelector('input[name=res]').value;

        if(isNaN(parseInt(res))){
            alert('请输入正确的数字')
            return
        }

        if(parseInt(res) > 100 || parseInt(res) < 0){
            alert('请输入0-100之间的数字');
            return
        }

        const realSubmitBtn = document.querySelector('#submit');

        realSubmitBtn.click();
    }
</script>

</body>

</html>